//7.观察者模式之redux
function createStore(reducer) { 
    let state;
    let listeners = [];
    function getState( ) { 
        return state;
     }
    function subscribe(listener) { 
        listeners.push(listener);
     };
    function dispatch(action) { 
         state = reducer(state,action);
         listeners.forEach(item=>{
             item();
         })
      }
      return {
          getState,
          subscribe,
          dispatch
      }
 }